package com.magicsoft.share.presenter.main;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.main.User;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.view.main.IInputPasswordView;

/**
 * Created by lyf on 2017/11/16/016.
 */

public class InputPasswordPresenter extends BasePresenter<IInputPasswordView> {


    public void editUserDetail(String oldPassword, String password) {
        RetrofitUtil.getApi(APIService.class).editUserDetail(SPUtils.getInstance().getString(SPKey.TOKEN)
                , SPUtils.getInstance().getLong(SPKey.ID)
                , oldPassword, password, null, null, null, null, null)
                .compose(new NetWorkTransformer())
                .compose(new LoadingTransformer(mContext))
                .subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(Object o) {

                        getView().editUserDetailSuccess();
                    }
                });
    }

    public void register(String phone, String password, String smsCode) {

        RetrofitUtil.getApi(APIService.class).
                userRegister(phone, password, smsCode).
                compose(new NetWorkTransformer()).
                compose(new LoadingTransformer(mContext)).
                subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(Object o) {

                        getView().registerSuccess();
                    }
                });

    }

    public void login(String phone, String password) {
        RetrofitUtil
                .getApi(APIService.class)
                .userLogin(phone, password)
                .compose(new NetWorkTransformer<User>())
                .compose(new LoadingTransformer<User>(mContext))
                .subscribe(new SimpleObserver<User>(mCompositeDisposable) {
                    @Override
                    public void call(User user) {

                        getView().loginSuccess(user);
                    }
                });

    }
}
